from django.http import HttpResponse, Http404, StreamingHttpResponse, FileResponse
from django.shortcuts import render


def index(request):
    return render(request, 'download.html')


def download1(request):
    file_path = r"D:\upload\01-网页制作.zip"
    try:
        r = HttpResponse(open(file_path, 'rb'))
        r['Content-Type'] = 'application/octet-stream'
        r['Content-Disposition'] = 'attachment; filename="01-网页制作.zip'
        return r
    except Exception:
        return Http404('Download error')


def download2(request):
    file_path = r"D:\upload\01-网页制作.zip"
    try:
        r = StreamingHttpResponse(open(file_path, 'rb'))
        r['Content-Type'] = 'application/octet-stream'
        r['Content-Disposition'] = 'attachment; filename="01-网页制作.zip'
        return r
    except Exception:
        raise Http404('Download error')


def download3(request):
    file_path = r"D:\upload\01-网页制作.zip"
    try:
        f = open(file_path, 'rb')
        r = FileResponse(f, as_attachment=True, filename="01-网页制作.zip")
        return r
    except Exception:
        raise Http404('Download error')
